package test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class BeanxmlFactory {
	private ConfigurableApplicationContext applicationContext;
	
	private static BeanxmlFactory beanxmlFactory;
	
	private BeanxmlFactory(){
		if(applicationContext == null){
			this.applicationContext=(ConfigurableApplicationContext) getContextFromFireSystem(getConfigLocations());
		}
	}
	private String[] getConfigLocations() {
		String[] config = new String[] { "file:F:\\JavaSoft\\eclipse-jee-europa-win32\\work\\pxto\\build\\classes\\test\\spring-config.xml","file:F:\\JavaSoft\\eclipse-jee-europa-win32\\work\\pxto\\build\\classes\\test\\spring-dao.xml","file:F:\\JavaSoft\\eclipse-jee-europa-win32\\work\\pxto\\build\\classes\\test\\spring-service.xml" };
		return config;
	}
	private ApplicationContext getContextFromClassPath(String[] filePath) {
		return new ClassPathXmlApplicationContext(filePath);
	}
	private ApplicationContext getContextFromFireSystem(String[] filePath) {
		return new FileSystemXmlApplicationContext(filePath);
	}
	
	public  Object getBean(String name){
		return applicationContext.getBean(name);
		
	}
	
	public static BeanxmlFactory getInstance(){
		if(beanxmlFactory == null){
			return new BeanxmlFactory();
		}else{
			return beanxmlFactory;
		}
	}
	
}
